package ioc

import (
	"context"
	"jk-time/webook/internal/domain"
	"jk-time/webook/internal/service"
	job2 "jk-time/webook/internal/web/job"
	"time"
)

func InitScheduler(svc service.JobService, localFuncExecutor *job2.LocalFuncExecutor) *job2.Scheduler {
	res := job2.NewScheduler(svc)
	res.RegisterExecutor(localFuncExecutor)
	return res
}
func InitLocalFuncExcutor(svc service.RankingService) *job2.LocalFuncExecutor {
	res := job2.NewLocalFuncExecutor()
	res.Register("ranking", func(ctx context.Context, j domain.Job) error {
		ctx, cancel := context.WithTimeout(ctx, time.Second*30)
		defer cancel()
		return svc.TopN(ctx)
	})
	return res
}
